<?php

namespace api\admin\controller;

class AdminIndexController extends \Aaa\admin\controller\AdminIndexController {
    public $baseField = [
        [
            'field' => 'id',
            'name' => 'ID',
        ],
        [
            'field' => 'user_id',
            'name' => '用户ID',
        ],
        [
            'field' => 'admin_role_id',
            'name' => '管理员角色',
            'placeholder' => '请输入备注',
            'type' => 'select',
            'optionsSource' => [
                'table' => 'admin_role',
                'nameField' => 'name',
                'valueField' => 'id',
            ],
        ],
        [
            'field' => 'remark',
            'name' => '备注',
        ],
        [
            'field' => 'create_time',
            'name' => '添加时间',
            'type' => 'time',
        ],
        [
            'field' => 'update_time',
            'name' => '修改时间',
            'type' => 'time',
        ],
    ];

    protected function beforeIndex() {
        $this->searchField = [
            'common' => [
                'user_id' => 'accurate',
                'remark' => 'fuzzy',
            ],
            'time' => ['create_time', 'update_time'],
        ];
    }

    protected function beforeAdd() {
        $this->actionField = ['user_id', 'admin_role_id', 'remark',];
    }

    protected function beforeEdit() {
        $this->beforeAdd();
    }

    protected function beforeEditPost() {
        if (is_array($this->paramId)) {
            $this->error('创始人管理员禁止修改', !in_array(1, $this->paramId));
        } else {
            $this->error('创始人管理员禁止修改', $this->paramId != 1);
        }
        if ($this->isDemo) {
            if (is_array($this->paramId)) {
                $this->error('测试管理员禁止修改', !in_array(2, $this->paramId));
            } else {
                $this->error('测试管理员禁止修改', $this->paramId != 2);
            }
        }
    }

    protected function beforeDeletePost() {
        if (is_array($this->paramId)) {
            $this->error('创始人管理员禁止删除', !in_array(1, $this->paramId));
        } else {
            $this->error('创始人管理员禁止删除', $this->paramId != 1);
        }
        if ($this->isDemo) {
            if (is_array($this->paramId)) {
                $this->error('测试管理员禁止删除', !in_array(2, $this->paramId));
            } else {
                $this->error('测试管理员禁止删除', $this->paramId != 2);
            }
        }
    }

}
